<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<script th:inline="javascript">
var mapPrompt = new MyMap();
[# th:each="option : ${options}"]
	mapPrompt.put('[(${option.value})]', '[(${rootPath})]/showImgInJar?path=[(${option.path})]');
[/]

// 匿名函数
(async function() {
    // 加载图标
    var ary = mapPrompt.getElements();
    var len = ary.length;
    for (var k=len-1; k>=0; k--) {
        let key = ary[k].key;
        let val = ary[k].value;
        if (typeof loadImgInJar == 'function') {
            // mapPrompt.remove(key);
            // 在项目编辑页面await后就会执行formatStatePrompt，结果mapPrompt因为被remove了，长度就变为了2，致取不到绿灯，故改写了mymap.js，在put的时候检查如果存在key则删除
            var buf = await loadImgInJar(val);
            mapPrompt.put(key, buf);
        } else {
            console.error('loadImgInJar is not function.');
        }
    }
    // console.log('mapPrompt', mapPrompt);
})();

function formatStatePrompt(state) {
    if (!state.id) { return state.text; }
    if (mapPrompt.get(state.id)) {
        console.log('formatStatePrompt', mapPrompt.get(state.id).value);
        // mapPrompt中键值对应的为state.id
        var $state = $(
            '<span><img src="' + mapPrompt.get(state.id).value + '" class="img-flag" /> ' + state.text + '</span>'
        );
        /*if (typeof loadImgByJQueryObj == 'function') {
            loadImgByJQueryObj($state);
        }*/
        return $state;
    } else {
        console.error('mapPrompt has not key: ', state.id, 'mapPrompt', mapPrompt);
    }
}
</script>
</body>
</html>